{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <form class="layui-form gg-form-bar border-x border-t" lay-filter="barsearchform">

        <!--<div class="layui-inline">-->
        <!--<label class="layui-form-label">关键字</label>-->
        <!--<div class="layui-input-inline" style="width:200px;">-->
        <!--<input type="text" name="keywords" placeholder="输入公司或客户名称" class="layui-input" autocomplete="off"/>-->
        <!--</div>-->
        <!--</div>-->

        <!--<div class="layui-input-inline" style="width:150px;">-->
        <!--<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i-->
        <!--class="layui-icon layui-icon-search mr-1"></i>搜索-->
        <!--</button>-->
        <!--<button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>-->
        <!--</div>-->
    </form>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
    <button type="button" class="layui-btn" id="import-rs">
        <i class="layui-icon">&#xe67c;</i>人社数据导入（仅支持xlsx）
    </button>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    // {
    //     field: 'check_status', title: '状态', align: 'center', width: 200, templet: function (d) {
    //     var html = '<span class="layui-btn layui-btn-xs layui-bg-' + d.check_status + '">' + d.status_name + '</span>';
    //     return html;
    // }
    // },
    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form;
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#import-rs' //绑定元素
                , accept: 'file'
                , url: '/rszs/rszs/add' //上传接口
                , done: function (res) {
                    layer.msg(res.msg);
                    tempInterval = setTimeout(function() {
                        location.reload();
                    }, 1500); //10秒刷新一次
                }
                , error: function (error) {
                    layer.msg('导入失败！');
                    layer.close();
                }
            });
        });
        layui.pageTable = table.render({
            elem: '#test',
            title: '导入记录',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', {title: '导出EXCEL', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-export'}],
            url: "/rszs/rszs/index", //数据接口
            cellMinWidth: 80,
            page: true, //开启分页
            limit: 20,
            cols: [
                [ //表头
                    {
                        field: 'id',
                        title: '编号',
                        align: 'center',
                        width: 80,
                        templet: function (d) {
                            return d.LAY_INDEX + 1
                        }
                    }, {
                    field: 'number',
                    title: '参保人数',
                    align: 'center',
                }, {
                    field: 'users',
                    title: '人员信息',
                    align: 'center',
                }, {
                    field: 'admin_name',
                    title: '导入人',
                    align: 'center',
                    width: 200
                }, {
                    field: 'create_time',
                    title: '导入日期',
                    align: 'center',
                }, {
                    field: 'is_qrcode',
                    title: '是否生成二维码',
                    align: 'center',
                },{
                    field: 'download_num',
                    title: '下载次数',
                    align: 'center',
                },
                    {
                        field: 'right',
                        title: '操作',
                        align: 'center',
                        templet: function (d) {
                            var btn5 = '';
                            var btn3 = '';
                            var html = '<div class="layui-btn-group">';
                            var btn4 = '<span class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail" style="background-color: #5fb878">参保详情</span>';
                            if (d.is_qrcode == '是') {
                                btn5 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="download">一键下载</span>';
                            }else{
                                btn3 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="qrcode-create" style="background-color:#B8A90D">二维码生成</span>';
                            }

                            btn2 = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>';

                            return html + btn4 +btn3+ btn5 + btn2+'</div>';
                        }
                    }
                ]
            ]
        });

        //表头工具栏事件
        table.on('toolbar(test)', function (obj) {
            if (obj.event === 'add') {
                tool.side('/cert/accountopen/add');
                return;
            }
            if (obj.event === 'LAYTABLE_EXCEL') {
                var formSelect = form.val('barsearchform');
                formSelect.limit = 99999;
                $.ajax({
                    url: '/rszs/rszs/index',
                    data: formSelect,
                    success: function (res) {
                        table.exportFile('test', res.data, 'xls');
                    }
                });
                return;
            }
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;

            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("/rszs/rszs/delete", {id: data.id}, callback);
                    layer.close(index);
                });
            }

            if (obj.event === 'detail') {
                tool.side('/rszs/rszs/detail?rszs_log_id=' + data.id);
                return;
            }


            if (obj.event === 'qrcode-create') {

                let shoucallback = function (e) {
                    layer.msg(e.msg);
                    if (e.code == 0) {
                        //定时30s刷新一次表格
                        tempInterval = setTimeout(function() {
                            location.reload();
                        }, 1500); //10秒刷新一次
                    }
                }
                tool.post("/rszs/rszs/qrcode_create", {'id': data.id}, shoucallback);
            }
            if (obj.event === 'download') {
                location.href = '/rszs/rszs/download?id='+data.id;
                return;
            }
        });

        //监听搜索提交
        form.on('submit(webform)', function (data) {
            layui.pageTable.reload({
                where: {
                    keywords: data.field.keywords,
                    cate_id: data.field.cate_id,
                    type: data.field.type,
                    check_status: data.field.check_status
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->
